package com.conversationboard.model;

import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

public class SearchResultUtilities {

    private SearchResultUtilities() {
    }


    /* Take out private threads if you are not on these boards */
    
    public static void removePrivateThreads(List<SearchResult> results, User user) throws SQLException {

        List<SearchResult> toBeRemoved = new LinkedList<SearchResult>();

        for (SearchResult result : results) {

            int boardId = result.getBoardId();

            if (Boards.getBoard(boardId).isPrivateBoard()) {
            	if (!user.isMemberOfBoard(boardId)) {
            		toBeRemoved.add(result);
            	}
            }

        }

        for (SearchResult result : toBeRemoved) {
            results.remove(result);
        }

    }

}
